import 'package:flutter/material.dart';
import 'package:flutter_ume/ui/home_pages/find_pager.dart';
import 'package:flutter_ume/ui/home_pages/home_pager.dart';
import 'package:flutter_ume/ui/home_pages/mine_pager.dart';

import 'package:flutter_ume/common/component_index.dart';

class TabNavigator extends StatefulWidget {
  @override
  _TabNavigatorState createState() => _TabNavigatorState();
}

class _TabNavigatorState extends State<TabNavigator> {
  PageController _controller;

  final _defaultColor = Color.fromARGB(255, 98, 98, 98);
  final _activeColor = Color.fromARGB(255, 204, 153, 51);
  int _currentIndex;

  @override
  void initState() {
    super.initState();
    _currentIndex = 0;
    _controller = PageController(initialPage: 0);
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    // TODO: implement build

    return Scaffold(
      body: PageView(
        controller: _controller,
        physics: NeverScrollableScrollPhysics(),
        children: <Widget>[HomePage(), FindPage(), MinePage()],
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          type: BottomNavigationBarType.fixed,
          onTap: (index) {
            print("点击了第$index个tab");
            print("_controller：$_controller");
            _controller.jumpToPage(index);
            setState(() {
              _currentIndex = index;
            });
          },
          items: [
            BottomNavigationBarItem(
                icon: Icon(Icons.home, color: _defaultColor),
                activeIcon: Icon(Icons.home, color: _activeColor),
                title: Text(
                  '首页',
                  style: TextStyle(
                      color: _currentIndex == 0 ? _activeColor : _defaultColor),
                )),
            BottomNavigationBarItem(
                icon: Icon(Icons.find_in_page, color: _defaultColor),
                activeIcon: Icon(Icons.find_in_page, color: _activeColor),
                title: Text(
                  '发现',
                  style: TextStyle(
                      color: _currentIndex == 1 ? _activeColor : _defaultColor),
                )),
            BottomNavigationBarItem(
                icon: Icon(Icons.person, color: _defaultColor),
                activeIcon: Icon(Icons.person, color: _activeColor),
                title: Text(
                  '我的',
                  style: TextStyle(
                      color: _currentIndex == 2 ? _activeColor : _defaultColor),
                ))
          ]),
    );
  }
}
